<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>div to img demo</title>
    <script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
    <script type="text/javascript" src="../js/html2canvas.js"></script>
    <style type="text/css">
        .content {
            display: block;
            position: relative;
            width: 300px;
            height: 300px;
            background-color: #E6B246
        }
    </style>
</head>

<body>
    <div class="layui-form-item">
        <label class="layui-form-label">专题图片</label>
        <div class="layui-input-inline">
            <div class="layui-upload-list">
                <img class="layui-upload-img" name="titleBase64Img" id="base64Img" src="" style="display: none" width="300px" height="100px;">
            </div>
            <input type="file" id="image" lay-verify="required" onchange="toBase64()" accept="image/jpeg,image/png,image/jpg" class="layui-upload-button">
        </div>
    </div>
</body>
<img id="testImg" alt="test" src="" />

</html>

<script type="text/javascript">
    function toBase64() {
        var file = document.querySelector('input[type=file]').files[0];
        var reader = new FileReader();
        reader.onloadend = function() {
            $("#base64Img").attr("style", "display:inline-block");
            $("#base64Img").attr("src", reader.result);
            console.log(reader.result);
        }
        if (file) {
            reader.readAsDataURL(file);
        }
    }
</script>